<?php
defined('BY_JYA') or exit('error');
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$merch_setting = $this->plugin_setting('merch_setting');
if($_RQ['op']=='get'){
	$item=pdo_get('jy_tour_merch',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(empty($item)){
		$member = pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','realname','credit2','mobile','groupid','avatar','nickname'));
		$item =array(
			'merchname'=>$member['nickname'],
			'realname'=>$member['realname'],
			'mobile'=>$member['mobile'],
			'logo'=>$member['avatar'],
		);
	}
	$return['set']=$merch_setting;
	$return['item']=$item;
	$return['set']['regbg']=tomedia($return['set']['regbg']);
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['realname']){
		exi('请填写姓名','error');
	}
	if(!$postdata['mobile']){
		exi('请填写手机号','error');
	}
	$log=pdo_get('jy_tour_merch',array('uniacid'=>$_SESSION['uniacid'],'uname'=>$postdata['uname']));
	if($log){
		exi('用户名已被注册','error');
	}
	$data =array(
		'uname'=>$postdata['uname'],
		'upass'=>base64_encode($postdata['upass']),
		'applytime'=>time(),
		'mobile'=>$postdata['mobile'],
		'realname'=>$postdata['realname'],
		'merchname'=>$postdata['merchname'],
		'desc'=>$postdata['desc'],
		'salecate'=>$postdata['salecate'],
		'status'=>$merch_setting['isshenhe']?0:1,
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid']
	);
	pdo_insert('jy_tour_merch',$data);
	exi('已申请,请等待审核','','jy_tour/index/');
}
?>